﻿/**
 * jQuery EasyUI 1.2.2
 * 
 * Licensed under the GPL: http://www.gnu.org/licenses/gpl.txt
 * 
 * Copyright 2010 stworthy [ stworthy@gmail.com ]
 * 
 */
(function($) {
    $.extend(Array.prototype, {
                indexOf : function(o) {
                    for (var i = 0, _1 = this.length; i < _1; i++) {
                        if (this[i] == o) {
                            return i;
                        }
                    }
                    return -1;
                },
                remove : function(o) {
                    var _2 = this.indexOf(o);
                    if (_2 != -1) {
                        this.splice(_2, 1);
                    }
                    return this;
                }
            });
    function _3(_4, _5) {
        var _6 = $.data(_4, "datagrid").options;
        var _7 = $.data(_4, "datagrid").panel;
        if (_5) {
            if (_5.width) {
                _6.width = _5.width;
            }
            if (_5.height) {
                _6.height = _5.height;
            }
        }
        if (_6.fit == true) {
            var p = _7.panel("panel").parent();
            _6.width = p.width();
            _6.height = p.height();
        }
        _7.panel("resize", {
                    width : _6.width,
                    height : _6.height
                });
    };
    function _8(_9) {
        var _a = $.data(_9, "datagrid").options;
        var _b = $.data(_9, "datagrid").panel;
        var _c = _b.width();
        var _d = _b.height();
        var _e = _b.children("div.datagrid-view");
        var _f = _e.children("div.datagrid-view1");
        var _10 = _e.children("div.datagrid-view2");
        _e.width(_c);
        _f.width(_f.find("table").width());
        _10.width(_c - _f.outerWidth());
        _f.children("div.datagrid-header,div.datagrid-body,div.datagrid-footer").width(_f.width());
        _10.children("div.datagrid-header,div.datagrid-body,div.datagrid-footer").width(_10.width());
        var hh;
        var _11 = _f.children("div.datagrid-header");
        var _12 = _10.children("div.datagrid-header");
        var _13 = _11.find("table");
        var _14 = _12.find("table");
        _11.css("height", "");
        _12.css("height", "");
        _13.css("height", "");
        _14.css("height", "");
        hh = Math.max(_13.height(), _14.height());
        _13.height(hh);
        _14.height(hh);
        if ($.boxModel == true) {
            _11.height(hh - (_11.outerHeight() - _11.height()));
            _12.height(hh - (_12.outerHeight() - _12.height()));
        } else {
            _11.height(hh);
            _12.height(hh);
        }
        if (_a.height != "auto") {
            var _15 = _d - _10.children("div.datagrid-header").outerHeight(true)
                    - _10.children("div.datagrid-footer").outerHeight(true)
                    - _b.children("div.datagrid-toolbar").outerHeight(true)
                    - _b.children("div.datagrid-pager").outerHeight(true);
            _f.children("div.datagrid-body").height(_15);
            _10.children("div.datagrid-body").height(_15);
        }
        _e.height(_10.height());
        _10.css("left", _f.outerWidth());
    };
    function setGridHeight(_17, _18) {
        var rows = $.data(_17, "datagrid").data.rows;
        var opts = $.data(_17, "datagrid").options;
        var _1b = $.data(_17, "datagrid").panel;
        var _1c = _1b.children("div.datagrid-view");
        var view1 = _1c.children("div.datagrid-view1");
        var view2 = _1c.children("div.datagrid-view2");
        if (!view1.find("div.datagrid-body-inner").is(":empty")) {
            if (_18 >= 0) {
                setRowHeight(_18);
            } else {
                for (var i = 0; i < rows.length; i++) {
                    setRowHeight(i);
                }
                if (opts.showFooter) {
                    var _20 = $.data(_17, "datagrid").data.footer || [];
                    var c1 = view1.children("div.datagrid-footer");
                    var c2 = view2.children("div.datagrid-footer");
                    for (var i = 0; i < _20.length; i++) {
                        setRowHeight(i, c1, c2);
                    }
                    _8(_17);
                }
            }
        }
        if (opts.height == "auto") {
            var _21 = view1.children("div.datagrid-body");
            var _22 = view2.children("div.datagrid-body");
            var _23 = 0;
            var _24 = 0;
            _22.children().each(function() {
                        var c = $(this);
                        if (c.is(":visible")) {
                            _23 += c.outerHeight();
                            if (_24 < c.outerWidth()) {
                                _24 = c.outerWidth();
                            }
                        }
                    });
            if (_24 > _22.width()) {
                _23 += 18;
            }
            _21.height(_23);
            _22.height(_23);
            _1c.height(view2.height());
        }
        view2.children("div.datagrid-body").triggerHandler("scroll");
        function setRowHeight(rowIndex, c1, c2) {
            c1 = c1 || view1;
            c2 = c2 || view2;
            var tr1 = c1.find("tr[datagrid-row-index=" + rowIndex + "]");
            var tr2 = c2.find("tr[datagrid-row-index=" + rowIndex + "]");
            tr1.css("height", "");
            tr2.css("height", "");
            var _26 = Math.max(tr1.height(), tr2.height());
            tr1.css("height", _26);
            tr2.css("height", _26);
        };
    };
    /**
     * 初始化grid ,
     * 如果原来的参数中提供列说明，那么根据这里的列信息获取col信息
     */
    function initGrid(grid, _29) {
        function parseThead(_2b) {
            var _2c = [];
            $("tr", _2b).each(function() {
                        var _2d = [];
                        $("th", this).each(function() {
                                    var th = $(this);
                                    var col = {
                                        title : th.html(),
                                        align : th.attr("align") || "left",
                                        sortable : th.attr("sortable") == "true" || false,
                                        checkbox : th.attr("checkbox") == "true" || false
                                    };
                                    if (th.attr("field")) {
                                        col.field = th.attr("field");
                                    }
                                    if (th.attr("formatter")) {
                                        col.formatter = eval(th.attr("formatter"));
                                    }
                                    if (th.attr("styler")) {
                                        col.styler = eval(th.attr("styler"));
                                    }
                                    if (th.attr("editor")) {
                                        var s = $.trim(th.attr("editor"));
                                        if (s.substr(0, 1) == "{") {
                                            col.editor = eval("(" + s + ")");
                                        } else {
                                            col.editor = s;
                                        }
                                    }
                                    if (th.attr("rowspan")) {
                                        col.rowspan = parseInt(th.attr("rowspan"));
                                    }
                                    if (th.attr("colspan")) {
                                        col.colspan = parseInt(th.attr("colspan"));
                                    }
                                    if (th.attr("width")) {
                                        col.width = parseInt(th.attr("width"));
                                    }
                                    if (th.attr("hidden")) {
                                        col.hidden = th.attr("hidden") == "true";
                                    }
                                    _2d.push(col);
                                });
                        _2c.push(_2d);
                    });
            return _2c;
        };
        var _2e = $("<div class=\"datagrid-wrap\">" + "<div class=\"datagrid-view\">"
                + "<div class=\"datagrid-view1\">" 
                  + "<div class=\"datagrid-header\">" + "<div class=\"datagrid-header-inner\"></div>" + "</div>"
                  + "<div class=\"datagrid-body\">" + "<div class=\"datagrid-body-inner\"></div>" + "</div>"
                  + "<div class=\"datagrid-footer\">" + "<div class=\"datagrid-footer-inner\"></div>" + "</div>" 
                + "</div>"
                + "<div class=\"datagrid-view2\">"
                  + "<div class=\"datagrid-header\">" + "<div class=\"datagrid-header-inner\"></div>" + "</div>"
                  + "<div class=\"datagrid-body\"></div>"
                  + "<div class=\"datagrid-footer\">" + "<div class=\"datagrid-footer-inner\"></div>" + "</div>"
                + "</div>"
                + "<div class=\"datagrid-resize-proxy\"></div>"
                + "</div>" + "</div>").insertAfter(grid);
        _2e.panel({
                    doSize : false
                });
        _2e.panel("panel").addClass("datagrid").bind("_resize", function(e, _2f) {
                    var _30 = $.data(grid, "datagrid").options;
                    if (_30.fit == true || _2f) {
                        _3(grid);
                        setTimeout(function() {
                                    _31(grid);
                                }, 0);
                    }
                    return false;
                });
        $(grid).hide().appendTo(_2e.children("div.datagrid-view"));
        var _32 = parseThead($("thead[frozen=true]", grid));
        var _33 = parseThead($("thead[frozen!=true]", grid));
        return {
            panel : _2e,
            frozenColumns : _32,
            columns : _33
        };
    };
    function _34(grid) {
        var data = {
            total : 0,
            rows : []
        };
        var columns = ConvertColumns(grid, true).concat(ConvertColumns(grid, false));
        $(grid).find("tbody tr").each(function() {
                    data.total++;
                    var col = {};
                    for (var i = 0; i < columns.length; i++) {
                        col[columns[i]] = $("td:eq(" + i + ")", this).html();
                    }
                    data.rows.push(col);
                });
        return data;
    };
    function drawGridFrame(_3a) {
        var _3b = $.data(_3a, "datagrid").options;
        var _3c = $.data(_3a, "datagrid").panel;
        _3c.panel($.extend({}, _3b, {
                    doSize : false,
                    onResize : function(_3d, _3e) {
                        setTimeout(function() {
                                    _8(_3a);
                                    _6e(_3a);
                                    _3b.onResize.call(_3c, _3d, _3e);
                                }, 0);
                    },
                    onExpand : function() {
                        _8(_3a);
                        setGridHeight(_3a);
                        _3b.onExpand.call(_3c);
                    }
                }));
        var _3f = _3c.children("div.datagrid-view");
        var _40 = _3f.children("div.datagrid-view1");
        var _41 = _3f.children("div.datagrid-view2");
        //表头开始；
        drawHeader(_40.find("div.datagrid-header-inner"), _3b.frozenColumns, true);
        drawHeader(_41.find("div.datagrid-header-inner"), _3b.columns, false);
        //表头结束；
        //表底部数据开始
        _40.find("div.datagrid-footer-inner").css("display", _3b.showFooter ? "block" : "none");
        _41.find("div.datagrid-footer-inner").css("display", _3b.showFooter ? "block" : "none");
        //表底部数据结束
        //表的工具栏开始
        $("div.datagrid-toolbar", _3c).remove();
        if (_3b.toolbar) {
            var tb = $("<div class=\"datagrid-toolbar\"></div>").prependTo(_3c);
            for (var i = 0; i < _3b.toolbar.length; i++) {
                var btn = _3b.toolbar[i];
                if (btn == "-") {
                    $("<div class=\"datagrid-btn-separator\"></div>").appendTo(tb);
                } else {
                    var _43 = $("<a href=\"javascript:void(0)\"></a>");
                    _43[0].onclick = eval(btn.handler || function() {
                    });
                    _43.css("float", "left").appendTo(tb).linkbutton($.extend({}, btn, {
                                plain : true
                            }));
                }
            }
        }
        //表的工具栏结束
        //表的分页开始
        $("div.datagrid-pager", _3c).remove();
        if (_3b.pagination) {
            var _44 = $("<div class=\"datagrid-pager\"></div>").appendTo(_3c);
            _44.pagination({
                        pageNumber : _3b.pageNumber,
                        pageSize : _3b.pageSize,
                        pageList : _3b.pageList,
                        onSelectPage : function(_45, _46) {
                            _3b.pageNumber = _45;
                            _3b.pageSize = _46;
                            _139(_3a);
                        }
                    });
            _3b.pageSize = _44.pagination("options").pageSize;
        }
        //表的分页结束；
        function drawHeader(headDiv, columns, frozen) {
            if (!columns) {
                return;
            }
            $(headDiv).empty();
            var t = $("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tbody></tbody></table>").appendTo(headDiv);
            for (var i = 0; i < columns.length; i++) {
                var tr = $("<tr></tr>").appendTo($("tbody", t));
                var cols = columns[i];
                for (var j = 0; j < cols.length; j++) {
                    var col = cols[j];
                    var tdHtml = "";
                    if (col.rowspan) {
                        tdHtml += "rowspan=\"" + col.rowspan + "\" ";
                    }
                    if (col.colspan) {
                        tdHtml += "colspan=\"" + col.colspan + "\" ";
                    }
                    var td = $("<td " + tdHtml + "></td>").appendTo(tr);
                    if (col.checkbox) {
                        td.attr("field", col.field);
                        $("<div class=\"datagrid-header-check\"></div>").html("<input type=\"checkbox\"/>")
                                .appendTo(td);
                    } else {
                        if (col.field) {
                            td.attr("field", col.field);
                            td
                                    .append("<div class=\"datagrid-cell\"><span></span><span class=\"datagrid-sort-icon\"></span></div>");
                            $("span", td).html(col.title);
                            $("span.datagrid-sort-icon", td).html("&nbsp;");
                            var cell = td.find("div.datagrid-cell");
                            col.boxWidth = $.boxModel ? (col.width - (cell.outerWidth() - cell.width())) : col.width;
                            cell.width(col.boxWidth);
                            cell.css("text-align", (col.align || "left"));
                        } else {
                            $("<div class=\"datagrid-cell-group\"></div>").html(col.title).appendTo(td);
                        }
                    }
                    if (col.hidden) {
                        td.hide();
                    }
                }
            }
            ///行号列；
            if (frozen && _3b.rownumbers) {
                var td = $("<td rowspan=\"" + _3b.frozenColumns.length
                        + "\"><div class=\"datagrid-header-rownumber\"></div></td>");
                if ($("tr", t).length == 0) {
                    td.wrap("<tr></tr>").parent().appendTo($("tbody", t));
                } else {
                    td.prependTo($("tr:first", t));
                }
            }
        };
    };
    function bindRowEvent(_4e) {
        var panel = $.data(grid, "datagrid").panel;
        var options = $.data(grid, "datagrid").options;
        var data = $.data(grid, "datagrid").data;
        var panel_body = panel.find("div.datagrid-body");
        panel_body.find("tr[datagrid-row-index]").unbind(".datagrid").bind("mouseenter.datagrid", function() {
                    var rowIndex = $(this).attr("datagrid-row-index");
                    panel_body.find("tr[datagrid-row-index=" + rowIndex + "]").addClass("datagrid-row-over");
                }).bind("mouseleave.datagrid", function() {
                    var rowIndex = $(this).attr("datagrid-row-index");
                    panel_body.find("tr[datagrid-row-index=" + rowIndex + "]").removeClass("datagrid-row-over");
                }).bind("click.datagrid", function() {
                    var rowIndex = $(this).attr("datagrid-row-index");
                    if (options.singleSelect == true) {
                        removeSelected(grid);
                        rowCheckedByIndex(grid, rowIndex);
                    } else {
                        if ($(this).hasClass("datagrid-row-selected")) {
                            _5b(grid, rowIndex);
                        } else {
                            rowCheckedByIndex(grid, rowIndex);
                        }
                    }
                    if (options.onClickRow) {
                        options.onClickRow.call(grid, rowIndex, data.rows[rowIndex]);
                    }
                }).bind("dblclick.datagrid", function() {
                    var rowIndex = $(this).attr("datagrid-row-index");
                    if (options.onDblClickRow) {
                        options.onDblClickRow.call(grid, rowIndex, data.rows[rowIndex]);
                    }
                }).bind("contextmenu.datagrid", function(e) {
                    var rowIndex = $(this).attr("datagrid-row-index");
                    if (options.onRowContextMenu) {
                        options.onRowContextMenu.call(grid, e, rowIndex, data.rows[rowIndex]);
                    }
                });
        panel_body.find("div.datagrid-cell-check input[type=checkbox]").unbind(".datagrid").bind("click.datagrid",
                function(e) {
                    var _58 = $(this).parent().parent().parent().attr("datagrid-row-index");
                    if (options.singleSelect) {
                        removeSelected(grid);
                        rowCheckedByIndex(grid, _58);
                    } else {
                        if ($(this).attr("checked")) {
                            rowCheckedByIndex(grid, _58);
                        } else {
                            _5b(grid, _58);
                        }
                    }
                    e.stopPropagation();
                });
    };
    function _5c(_5d) {
        var _5e = $.data(_5d, "datagrid").panel;
        var _5f = $.data(_5d, "datagrid").options;
        var _60 = _5e.find("div.datagrid-header");
        _60.find("td:has(div.datagrid-cell)").unbind(".datagrid").bind("mouseenter.datagrid", function() {
                    $(this).addClass("datagrid-header-over");
                }).bind("mouseleave.datagrid", function() {
                    $(this).removeClass("datagrid-header-over");
                }).bind("contextmenu.datagrid", function(e) {
                    var _61 = $(this).attr("field");
                    _5f.onHeaderContextMenu.call(_5d, e, _61);
                });
        _60.find("div.datagrid-cell").unbind(".datagrid").bind("click.datagrid", function() {
                    var _62 = $(this).parent().attr("field");
                    var opt = getColumnByField(_5d, _62);
                    if (!opt.sortable) {
                        return;
                    }
                    _5f.sortName = _62;
                    _5f.sortOrder = "asc";
                    var c = "datagrid-sort-asc";
                    if ($(this).hasClass("datagrid-sort-asc")) {
                        c = "datagrid-sort-desc";
                        _5f.sortOrder = "desc";
                    }
                    _60.find("div.datagrid-cell").removeClass("datagrid-sort-asc datagrid-sort-desc");
                    $(this).addClass(c);
                    if (_5f.onSortColumn) {
                        _5f.onSortColumn.call(_5d, _5f.sortName, _5f.sortOrder);
                    }
                    if (_5f.remoteSort) {
                        _139(_5d);
                    } else {
                        var _63 = $.data(_5d, "datagrid").data;
                        addData(_5d, _63);
                    }
                });
        _60.find("input[type=checkbox]").unbind(".datagrid").bind("click.datagrid", function() {
                    if (_5f.singleSelect) {
                        return false;
                    }
                    if ($(this).attr("checked")) {
                        _b2(_5d);
                    } else {
                        unSelectedAll(_5d);
                    }
                });
        var _64 = _5e.children("div.datagrid-view");
        var _65 = _64.children("div.datagrid-view1");
        var _66 = _64.children("div.datagrid-view2");
        _66.children("div.datagrid-body").unbind(".datagrid").bind("scroll.datagrid", function() {
                    _65.children("div.datagrid-body").scrollTop($(this).scrollTop());
                    _66.children("div.datagrid-header").scrollLeft($(this).scrollLeft());
                    _66.children("div.datagrid-footer").scrollLeft($(this).scrollLeft());
                });
        _60.find("div.datagrid-cell").resizable({
                    handles : "e",
                    minWidth : 25,
                    onStartResize : function(e) {
                        var _67 = _64.children("div.datagrid-resize-proxy");
                        _67.css({
                                    left : e.pageX - $(_5e).offset().left - 1
                                });
                        _67.css("display", "block");
                    },
                    onResize : function(e) {
                        var _68 = _64.children("div.datagrid-resize-proxy");
                        _68.css({
                                    display : "block",
                                    left : e.pageX - $(_5e).offset().left - 1
                                });
                        return false;
                    },
                    onStopResize : function(e) {
                        var _69 = $(this).parent().attr("field");
                        var col = getColumnByField(_5d, _69);
                        col.width = $(this).outerWidth();
                        col.boxWidth = $.boxModel == true ? $(this).width() : $(this).outerWidth();
                        _31(_5d, _69);
                        _6e(_5d);
                        var _6a = _5e.find("div.datagrid-view2");
                        _6a.find("div.datagrid-header").scrollLeft(_6a.find("div.datagrid-body").scrollLeft());
                        _64.children("div.datagrid-resize-proxy").css("display", "none");
                        _5f.onResizeColumn.call(_5d, _69, col.width);
                    }
                });
        $("div.datagrid-view1 div.datagrid-header div.datagrid-cell", _5e).resizable({
                    onStopResize : function(e) {
                        var _6b = $(this).parent().attr("field");
                        var col = getColumnByField(_5d, _6b);
                        col.width = $(this).outerWidth();
                        col.boxWidth = $.boxModel == true ? $(this).width() : $(this).outerWidth();
                        _31(_5d, _6b);
                        var _6d = _5e.find("div.datagrid-view2");
                        _6d.find("div.datagrid-header").scrollLeft(_6d.find("div.datagrid-body").scrollLeft());
                        _64.children("div.datagrid-resize-proxy").css("display", "none");
                        _5f.onResizeColumn.call(_5d, _6b, col.width);
                        _3(_5d);
                    }
                });
    };
    function _6e(_6f) {
        var _70 = $.data(_6f, "datagrid").options;
        if (!_70.fitColumns) {
            return;
        }
        var _71 = $.data(_6f, "datagrid").panel;
        var _72 = _71.find("div.datagrid-view2 div.datagrid-header");
        var _73 = 0;
        var _74 = ConvertColumns(_6f, false);
        for (var i = 0; i < _74.length; i++) {
            var col = getColumnByField(_6f, _74[i]);
            if (!col.hidden && !col.checkbox) {
                _73 += col.width;
            }
        }
        var _75 = (_72.width() - _72.find("table").width() - 18) / _73;
        for (var i = 0; i < _74.length; i++) {
            var col = getColumnByField(_6f, _74[i]);
            var _76 = col.width - col.boxWidth;
            var _77 = Math.floor(col.width + col.width * _75);
            col.width = _77;
            col.boxWidth = _77 - _76;
            _72.find("td[field=" + col.field + "] div.datagrid-cell").width(col.boxWidth);
        }
        _31(_6f);
    };
    function _31(grid, fieldName) {
        var $panel = $.data(grid, "datagrid").panel;
        var bf = $panel.find("div.datagrid-body,div.datagrid-footer");
        if (fieldName) {
            fix(fieldName);
        } else {
            $panel.find("div.datagrid-header td[field]").each(function() {
                        fix($(this).attr("field"));
                    });
        }
        _7d(grid);
        setTimeout(function() {
                    setGridHeight(grid);
                    _86(grid);
                }, 0);
        function fix(field) {
            var col = getColumnByField(grid, field);
            bf.find("td[field=" + field + "]").each(function() {
                        var td = $(this);
                        var colspan = td.attr("colspan") || 1;
                        if (colspan == 1) {
                            td.find("div.datagrid-cell").width(col.boxWidth);
                            td.find("div.datagrid-editable").width(col.width);
                        }
                    });
        };
    };
    function _7d(_7e) {
        var $panel = $.data(_7e, "datagrid").panel;
        var $header = $panel.find("div.datagrid-header");
        $panel.find("div.datagrid-body td.datagrid-td-merged").each(function() {
                    var td = $(this);
                    var _81 = td.attr("colspan") || 1;
                    var field = td.attr("field");
                    var _83 = $header.find("td[field=" + field + "]");
                    var _84 = _83.width();
                    for (var i = 1; i < _81; i++) {
                        _83 = _83.next();
                        _84 += _83.outerWidth();
                    }
                    var _85 = td.children("div.datagrid-cell");
                    if ($.boxModel == true) {
                        _85.width(_84 - (_85.outerWidth() - _85.width()));
                    } else {
                        _85.width(_84);
                    }
                });
    };
    function _86(_87) {
        var _88 = $.data(_87, "datagrid").panel;
        _88.find("div.datagrid-editable").each(function() {
                    var ed = $.data(this, "datagrid.editor");
                    if (ed.actions.resize) {
                        ed.actions.resize(ed.target, $(this).width());
                    }
                });
    };
    function getColumnByField(grid, _8a) {
        var options = $.data(grid, "datagrid").options;
        if (options.columns) {
            for (var i = 0; i < options.columns.length; i++) {
                var cols = options.columns[i];
                for (var j = 0; j < cols.length; j++) {
                    var col = cols[j];
                    if (col.field == _8a) {
                        return col;
                    }
                }
            }
        }
        if (options.frozenColumns) {
            for (var i = 0; i < options.frozenColumns.length; i++) {
                var cols = options.frozenColumns[i];
                for (var j = 0; j < cols.length; j++) {
                    var col = cols[j];
                    if (col.field == _8a) {
                        return col;
                    }
                }
            }
        }
        return null;
    };
    /**
     * 深度遍历列信息，将列信息从原来的二维数组，转换为一维数组
     */
    function ConvertColumns(grid, frozen) {
        var opts = $.data(grid, "datagrid").options;
        var columns = (frozen == true) ? (opts.frozenColumns || [[]]) : opts.columns;
        if (columns.length == 0) {
            return [];
        }
        var fieldCols = [];
        function calIndex(colIndex) {
            var c = 0;
            var i = 0;
            while (true) {
                if (fieldCols[i] == undefined) {
                    if (c == colIndex) {
                        return i;
                    }
                    c++;
                }
                i++;
            }
        };
        function depthTravel(r) {
            var ff = [];
            var c = 0;
            for (var i = 0; i < columns[r].length; i++) {
                var col = columns[r][i];
                if (col.field) {
                    ff.push([c, col.field]);
                }
                c += parseInt(col.colspan || "1");
            }
            for (var i = 0; i < ff.length; i++) {
                ff[i][0] = calIndex(ff[i][0]);
            }
            for (var i = 0; i < ff.length; i++) {
                var f = ff[i];
                fieldCols[f[0]] = f[1];
            }
        };
        for (var i = 0; i < columns.length; i++) {
            depthTravel(i);
        }
        return fieldCols;
    };
    //addData(grid,data);
    function addData(grid, data) {
        var options = $.data(grid, "datagrid").options;
        var panel = $.data(grid, "datagrid").panel;
        var selectedRows = $.data(grid, "datagrid").selectedRows;
        var rows = data.rows;
        $.data(grid, "datagrid").data = data;
        if (!options.remoteSort) {
            var opt = getColumnByField(grid, options.sortName);
            if (opt) {
                var sortFun = opt.sorter || function(a, b) {
                    return (a > b ? 1 : -1);
                };
                data.rows.sort(function(r1, r2) {
                            return sortFun(r1[options.sortName], r2[options.sortName]) * (options.sortOrder == "asc" ? 1 : -1);
                        });
            }
        }
        var grid_view = panel.children("div.datagrid-view");
        var grid_view1 = grid_view.children("div.datagrid-view1");
        var grid_view2 = grid_view.children("div.datagrid-view2");
        if (options.view.onBeforeRender) {
            options.view.onBeforeRender.call(options.view, grid, rows);
        }
        options.view.render.call(options.view, grid, grid_view2.children("div.datagrid-body"), false);
        options.view.render
                .call(options.view, grid, grid_view1.children("div.datagrid-body").children("div.datagrid-body-inner"), true);
        if (options.showFooter) {
            options.view.renderFooter.call(options.view, grid, grid_view2.find("div.datagrid-footer-inner"), false);
            options.view.renderFooter.call(options.view, grid, grid_view1.find("div.datagrid-footer-inner"), true);
        }
        if (options.view.onAfterRender) {
            options.view.onAfterRender.call(options.view, grid);
        }
        options.onLoadSuccess.call(grid, data);
        var _a0 = panel.children("div.datagrid-pager");
        if (_a0.length) {
            if (_a0.pagination("options").total != data.total) {
                _a0.pagination({
                            total : data.total
                        });
            }
        }
        setGridHeight(grid);
        bindRowEvent(grid);
        grid_view2.children("div.datagrid-body").triggerHandler("scroll");
        if (options.idField) {
            for (var i = 0; i < rows.length; i++) {
                if (_a1(rows[i])) {
                    rowCheckedById(grid, rows[i][options.idField]);
                }
            }
        }
        function _a1(row) {
            for (var i = 0; i < selectedRows.length; i++) {
                if (selectedRows[i][options.idField] == row[options.idField]) {
                    selectedRows[i] = row;
                    return true;
                }
            }
            return false;
        };
    };
    function _a2(_a3, row) {
        var _a4 = $.data(_a3, "datagrid").options;
        var _a5 = $.data(_a3, "datagrid").data.rows;
        if (typeof row == "object") {
            return _a5.indexOf(row);
        } else {
            for (var i = 0; i < _a5.length; i++) {
                if (_a5[i][_a4.idField] == row) {
                    return i;
                }
            }
            return -1;
        }
    };
    function _a6(_a7) {
        var _a8 = $.data(_a7, "datagrid").options;
        var _a9 = $.data(_a7, "datagrid").panel;
        var _aa = $.data(_a7, "datagrid").data;
        if (_a8.idField) {
            var _ab = $.data(_a7, "datagrid").deletedRows;
            var _ac = $.data(_a7, "datagrid").selectedRows;
            var _ad = [];
            for (var i = 0; i < _ac.length; i++) {
                (function() {
                    var row = _ac[i];
                    for (var j = 0; j < _ab.length; j++) {
                        if (row[_a8.idField] == _ab[j][_a8.idField]) {
                            return;
                        }
                    }
                    _ad.push(row);
                })();
            }
            return _ad;
        }
        var _ad = [];
        $("div.datagrid-view2 div.datagrid-body tr.datagrid-row-selected", _a9).each(function() {
                    var _ae = parseInt($(this).attr("datagrid-row-index"));
                    if (_aa.rows[_ae]) {
                        _ad.push(_aa.rows[_ae]);
                    }
                });
        return _ad;
    };
    function removeSelected(grid) {
        unSelectedAll(grid);
        var _b1 = $.data(grid, "datagrid").selectedRows;
        while (_b1.length > 0) {
            _b1.pop();
        }
    };
    function _b2(_b3) {
        var _b4 = $.data(_b3, "datagrid").options;
        var _b5 = $.data(_b3, "datagrid").panel;
        var _b6 = $.data(_b3, "datagrid").data;
        var _b7 = $.data(_b3, "datagrid").selectedRows;
        var _b8 = _b6.rows;
        var _b9 = _b5.find("div.datagrid-body");
        $("tr", _b9).addClass("datagrid-row-selected");
        $("div.datagrid-cell-check input[type=checkbox]", _b9).attr("checked", true);
        for (var _ba = 0; _ba < _b8.length; _ba++) {
            if (_b4.idField) {
                (function() {
                    var row = _b8[_ba];
                    for (var i = 0; i < _b7.length; i++) {
                        if (_b7[i][_b4.idField] == row[_b4.idField]) {
                            return;
                        }
                    }
                    _b7.push(row);
                })();
            }
        }
        _b4.onSelectAll.call(_b3, _b8);
    };
    function unSelectedAll(grid) {
        var opts = $.data(grid, "datagrid").options;
        var panel = $.data(grid, "datagrid").panel;
        var data = $.data(grid, "datagrid").data;
        var selectedRows = $.data(grid, "datagrid").selectedRows;
        $("div.datagrid-body tr.datagrid-row-selected", panel).removeClass("datagrid-row-selected");
        $("div.datagrid-body div.datagrid-cell-check input[type=checkbox]", panel).attr("checked", false);
        if (opts.idField) {
            for (var _c0 = 0; _c0 < data.rows.length; _c0++) {
                var id = data.rows[_c0][opts.idField];
                for (var i = 0; i < selectedRows.length; i++) {
                    if (selectedRows[i][_bc.idField] == id) {
                        selectedRows.splice(i, 1);
                        break;
                    }
                }
            }
        }
        opts.onUnselectAll.call(grid, data.rows);
    };
    function rowCheckedByIndex(grid, rowid) {
        var panel = $.data(grid, "datagrid").panel;
        var options = $.data(grid, "datagrid").options;
        var data = $.data(grid, "datagrid").data;
        var selectedRows = $.data(grid, "datagrid").selectedRows;
        if (rowid < 0 || rowid >= data.rows.length) {
            return;
        }
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + rowid + "]", panel);
        var ck = $("div.datagrid-cell-check input[type=checkbox]", tr);
        tr.addClass("datagrid-row-selected");
        ck.attr("checked", true);
        var panel_view2 = panel.find("div.datagrid-view2");
        var panel_view2_header_height = panel_view2.find("div.datagrid-header").outerHeight();
        var panel_view2_body = panel_view2.find("div.datagrid-body");
        var top = tr.position().top - panel_view2_header_height;
        if (top <= 0) {
            panel_view2_body.scrollTop(panel_view2_body.scrollTop() + top);
        } else {
            if (top + tr.outerHeight() > panel_view2_body.height() - 18) {
                panel_view2_body.scrollTop(panel_view2_body.scrollTop() + top + tr.outerHeight() - panel_view2_body.height() + 18);
            }
        }
        if (options.idField) {
            var row = data.rows[rowid];
            (function() {
                for (var i = 0; i < selectedRows.length; i++) {
                    if (selectedRows[i][options.idField] == row[options.idField]) {
                        return;
                    }
                }
                selectedRows.push(row);
            })();
        }
        options.onSelect.call(grid, rowid, data.rows[rowid]);
    };
    function rowCheckedById(grid, idValue) {
        var opts = $.data(grid, "datagrid").options;
        var data = $.data(grid, "datagrid").data;
        if (opts.idField) {
            var index = -1;
            for (var i = 0; i < data.rows.length; i++) {
                if (data.rows[i][opts.idField] == idValue) {
                    index = i;
                    break;
                }
            }
            if (_cf >= 0) {
                rowCheckedByIndex(_cb, index);
            }
        }
    };
    function _5b(_d0, _d1) {
        var _d2 = $.data(_d0, "datagrid").options;
        var _d3 = $.data(_d0, "datagrid").panel;
        var _d4 = $.data(_d0, "datagrid").data;
        var _d5 = $.data(_d0, "datagrid").selectedRows;
        if (_d1 < 0 || _d1 >= _d4.rows.length) {
            return;
        }
        var _d6 = _d3.find("div.datagrid-body");
        var tr = $("tr[datagrid-row-index=" + _d1 + "]", _d6);
        var ck = $("tr[datagrid-row-index=" + _d1 + "] div.datagrid-cell-check input[type=checkbox]", _d6);
        tr.removeClass("datagrid-row-selected");
        ck.attr("checked", false);
        var row = _d4.rows[_d1];
        if (_d2.idField) {
            for (var i = 0; i < _d5.length; i++) {
                var _d7 = _d5[i];
                if (_d7[_d2.idField] == row[_d2.idField]) {
                    for (var j = i + 1; j < _d5.length; j++) {
                        _d5[j - 1] = _d5[j];
                    }
                    _d5.pop();
                    break;
                }
            }
        }
        _d2.onUnselect.call(_d0, _d1, row);
    };
    function _d8(_d9, _da) {
        var _db = $.data(_d9, "datagrid").options;
        var _dc = $.data(_d9, "datagrid").panel;
        var _dd = $.data(_d9, "datagrid").data;
        var _de = $.data(_d9, "datagrid").editingRows;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _da + "]", _dc);
        if (tr.hasClass("datagrid-row-editing")) {
            return;
        }
        if (_db.onBeforeEdit.call(_d9, _da, _dd.rows[_da]) == false) {
            return;
        }
        tr.addClass("datagrid-row-editing");
        _df(_d9, _da);
        _86(_d9);
        _de.push(_dd.rows[_da]);
        _e0(_d9, _da, _dd.rows[_da]);
        _e1(_d9, _da);
    };
    function _e2(_e3, _e4, _e5) {
        var _e6 = $.data(_e3, "datagrid").options;
        var _e7 = $.data(_e3, "datagrid").panel;
        var _e8 = $.data(_e3, "datagrid").data;
        var _e9 = $.data(_e3, "datagrid").updatedRows;
        var _ea = $.data(_e3, "datagrid").insertedRows;
        var _eb = $.data(_e3, "datagrid").editingRows;
        var row = _e8.rows[_e4];
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _e4 + "]", _e7);
        if (!tr.hasClass("datagrid-row-editing")) {
            return;
        }
        if (!_e5) {
            if (!_e1(_e3, _e4)) {
                return;
            }
            var _ec = false;
            var _ed = {};
            var nd = _ee(_e3, _e4);
            for (var _ef in nd) {
                if (row[_ef] != nd[_ef]) {
                    row[_ef] = nd[_ef];
                    _ec = true;
                    _ed[_ef] = nd[_ef];
                }
            }
            if (_ec) {
                if (_ea.indexOf(row) == -1) {
                    if (_e9.indexOf(row) == -1) {
                        _e9.push(row);
                    }
                }
            }
        }
        tr.removeClass("datagrid-row-editing");
        _eb.remove(row);
        _f0(_e3, _e4);
        $(_e3).datagrid("refreshRow", _e4);
        if (!_e5) {
            _e6.onAfterEdit.call(_e3, _e4, row, _ed);
        } else {
            _e6.onCancelEdit.call(_e3, _e4, row);
        }
    };
    function _e0(_f1, _f2, _f3) {
        var _f4 = $.data(_f1, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _f2 + "]", _f4);
        if (!tr.hasClass("datagrid-row-editing")) {
            return;
        }
        tr.find("div.datagrid-editable").each(function() {
                    var _f5 = $(this).parent().attr("field");
                    var ed = $.data(this, "datagrid.editor");
                    ed.actions.setValue(ed.target, _f3[_f5]);
                });
    };
    function _ee(_f6, _f7) {
        var _f8 = $.data(_f6, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _f7 + "]", _f8);
        if (!tr.hasClass("datagrid-row-editing")) {
            return {};
        }
        var _f9 = {};
        tr.find("div.datagrid-editable").each(function() {
                    var _fa = $(this).parent().attr("field");
                    var ed = $.data(this, "datagrid.editor");
                    _f9[_fa] = ed.actions.getValue(ed.target);
                });
        return _f9;
    };
    function _fb(_fc, _fd) {
        var _fe = [];
        var _ff = $.data(_fc, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _fd + "]", _ff);
        tr.children("td").each(function() {
                    var cell = $(this).find("div.datagrid-editable");
                    if (cell.length) {
                        var ed = $.data(cell[0], "datagrid.editor");
                        _fe.push(ed);
                    }
                });
        return _fe;
    };
    function _100(_101, _102) {
        var _103 = _fb(_101, _102.index);
        for (var i = 0; i < _103.length; i++) {
            if (_103[i].field == _102.field) {
                return _103[i];
            }
        }
        return null;
    };
    function _df(_104, _105) {
        var opts = $.data(_104, "datagrid").options;
        var _106 = $.data(_104, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _105 + "]", _106);
        tr.children("td").each(function() {
                    var cell = $(this).find("div.datagrid-cell");
                    var _107 = $(this).attr("field");
                    var col = getColumnByField(_104, _107);
                    if (col && col.editor) {
                        var _108, _109;
                        if (typeof col.editor == "string") {
                            _108 = col.editor;
                        } else {
                            _108 = col.editor.type;
                            _109 = col.editor.options;
                        }
                        var _10a = opts.editors[_108];
                        if (_10a) {
                            var _10b = cell.outerWidth();
                            cell.addClass("datagrid-editable");
                            if ($.boxModel == true) {
                                cell.width(_10b - (cell.outerWidth() - cell.width()));
                            }
                            cell
                                    .html("<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td></td></tr></table>");
                            cell.find("table").attr("align", col.align);
                            $.data(cell[0], "datagrid.editor", {
                                        actions : _10a,
                                        target : _10a.init(cell.find("td"), _109),
                                        field : _107,
                                        type : _108
                                    });
                        }
                    }
                });
        setGridHeight(_104, _105);
    };
    function _f0(_10c, _10d) {
        var _10e = $.data(_10c, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _10d + "]", _10e);
        tr.children("td").each(function() {
                    var cell = $(this).find("div.datagrid-editable");
                    if (cell.length) {
                        var ed = $.data(cell[0], "datagrid.editor");
                        if (ed.actions.destroy) {
                            ed.actions.destroy(ed.target);
                        }
                        $.removeData(cell[0], "datagrid.editor");
                        var _10f = cell.outerWidth();
                        cell.removeClass("datagrid-editable");
                        if ($.boxModel == true) {
                            cell.width(_10f - (cell.outerWidth() - cell.width()));
                        }
                    }
                });
    };
    function _e1(_110, _111) {
        var _112 = $.data(_110, "datagrid").panel;
        var tr = $("div.datagrid-body tr[datagrid-row-index=" + _111 + "]", _112);
        if (!tr.hasClass("datagrid-row-editing")) {
            return true;
        }
        var vbox = tr.find(".validatebox-text");
        vbox.validatebox("validate");
        vbox.trigger("mouseleave");
        var _113 = tr.find(".validatebox-invalid");
        return _113.length == 0;
    };
    function _114(_115, _116) {
        var _117 = $.data(_115, "datagrid").insertedRows;
        var _118 = $.data(_115, "datagrid").deletedRows;
        var _119 = $.data(_115, "datagrid").updatedRows;
        if (!_116) {
            var rows = [];
            rows = rows.concat(_117);
            rows = rows.concat(_118);
            rows = rows.concat(_119);
            return rows;
        } else {
            if (_116 == "inserted") {
                return _117;
            } else {
                if (_116 == "deleted") {
                    return _118;
                } else {
                    if (_116 == "updated") {
                        return _119;
                    }
                }
            }
        }
        return [];
    };
    function _11a(_11b, _11c) {
        var data = $.data(_11b, "datagrid").data;
        var _11d = $.data(_11b, "datagrid").insertedRows;
        var _11e = $.data(_11b, "datagrid").deletedRows;
        var _11f = $.data(_11b, "datagrid").editingRows;
        var _120 = $.data(_11b, "datagrid").selectedRows;
        var row = data.rows[_11c];
        data.total -= 1;
        if (_11d.indexOf(row) >= 0) {
            _11d.remove(row);
            _120.remove(row);
        } else {
            _11e.push(row);
        }
        if (_11f.indexOf(row) >= 0) {
            _11f.remove(row);
            _f0(_11b, _11c);
        }
        var _121 = [];
        for (var i = 0; i < _11f.length; i++) {
            var idx = data.rows.indexOf(_11f[i]);
            _121.push(_ee(_11b, idx));
            _f0(_11b, idx);
        }
        data.rows.remove(row);
        addData(_11b, data);
        var _122 = [];
        for (var i = 0; i < _11f.length; i++) {
            var idx = data.rows.indexOf(_11f[i]);
            _122.push(idx);
        }
        _11f.splice(0, _11f.length);
        for (var i = 0; i < _122.length; i++) {
            _d8(_11b, _122[i]);
            _e0(_11b, _122[i], _121[i]);
        }
    };
    function _123(_124, row) {
        if (!row) {
            return;
        }
        var _125 = $.data(_124, "datagrid").panel;
        var data = $.data(_124, "datagrid").data;
        var _126 = $.data(_124, "datagrid").insertedRows;
        var _127 = $.data(_124, "datagrid").editingRows;
        data.total += 1;
        data.rows.push(row);
        _126.push(row);
        var _128 = [];
        for (var i = 0; i < _127.length; i++) {
            var idx = data.rows.indexOf(_127[i]);
            _128.push(_ee(_124, idx));
            _f0(_124, idx);
        }
        addData(_124, data);
        var _129 = [];
        for (var i = 0; i < _127.length; i++) {
            var idx = data.rows.indexOf(_127[i]);
            _129.push(idx);
        }
        _127.splice(0, _127.length);
        for (var i = 0; i < _129.length; i++) {
            _d8(_124, _129[i]);
            _e0(_124, _129[i], _128[i]);
        }
        var _12a = $("div.datagrid-view2 div.datagrid-body", _125);
        var _12b = _12a.children("table");
        var top = _12b.outerHeight() - _12a.outerHeight();
        _12a.scrollTop(top + 20);
    };
    function _12c(_12d) {
        var data = $.data(_12d, "datagrid").data;
        var rows = data.rows;
        var _12e = [];
        for (var i = 0; i < rows.length; i++) {
            _12e.push($.extend({}, rows[i]));
        }
        $.data(_12d, "datagrid").originalRows = _12e;
        $.data(_12d, "datagrid").updatedRows = [];
        $.data(_12d, "datagrid").insertedRows = [];
        $.data(_12d, "datagrid").deletedRows = [];
        $.data(_12d, "datagrid").editingRows = [];
    };
    function _12f(_130) {
        var data = $.data(_130, "datagrid").data;
        var ok = true;
        for (var i = 0, len = data.rows.length; i < len; i++) {
            if (_e1(_130, i)) {
                _e2(_130, i, false);
            } else {
                ok = false;
            }
        }
        if (ok) {
            _12c(_130);
        }
    };
    function _131(_132) {
        var opts = $.data(_132, "datagrid").options;
        var _133 = $.data(_132, "datagrid").originalRows;
        var _134 = $.data(_132, "datagrid").insertedRows;
        var _135 = $.data(_132, "datagrid").deletedRows;
        var _136 = $.data(_132, "datagrid").updatedRows;
        var _137 = $.data(_132, "datagrid").selectedRows;
        var data = $.data(_132, "datagrid").data;
        for (var i = 0; i < data.rows.length; i++) {
            _e2(_132, i, true);
        }
        var rows = [];
        var _138 = {};
        if (opts.idField) {
            for (var i = 0; i < _137.length; i++) {
                _138[_137[i][opts.idField]] = true;
            }
        }
        _137.splice(0, _137.length);
        for (var i = 0; i < _133.length; i++) {
            var row = $.extend({}, _133[i]);
            rows.push(row);
            if (_138[row[opts.idField]]) {
                _137.push(row);
            }
        }
        data.total += _135.length - _134.length;
        data.rows = rows;
        addData(_132, data);
        $.data(_132, "datagrid").updatedRows = [];
        $.data(_132, "datagrid").insertedRows = [];
        $.data(_132, "datagrid").deletedRows = [];
        $.data(_132, "datagrid").editingRows = [];
    };
    function _139(_13a, _13b) {
        var _13c = $.data(_13a, "datagrid").panel;
        var opts = $.data(_13a, "datagrid").options;
        if (_13b) {
            opts.queryParams = _13b;
        }
        if (!opts.url) {
            return;
        }
        var _13d = $.extend({}, opts.queryParams);
        if (opts.pagination) {
            $.extend(_13d, {
                        page : opts.pageNumber,
                        rows : opts.pageSize
                    });
        }
        if (opts.sortName) {
            $.extend(_13d, {
                        sort : opts.sortName,
                        order : opts.sortOrder
                    });
        }
        if (opts.onBeforeLoad.call(_13a, _13d) == false) {
            return;
        }
        setLoadBegin();
        setTimeout(function() {
                    _13f();
                }, 0);
        function _13f() {
            $.ajax({
                        type : opts.method,
                        url : opts.url,
                        data : _13d,
                        dataType : "json",
                        success : function(data) {
                            setTimeout(function() {
                                        setLoadEnd();
                                    }, 0);
                            addData(_13a, data);
                            setTimeout(function() {
                                        _12c(_13a);
                                    }, 0);
                        },
                        error : function() {
                            setTimeout(function() {
                                        setLoadEnd();
                                    }, 0);
                            if (opts.onLoadError) {
                                opts.onLoadError.apply(_13a, arguments);
                            }
                        }
                    });
        };
        function setLoadBegin() {
            _13c.children("div.datagrid-pager").pagination("loading");
            if (opts.loadMsg) {
                var wrap = _13c;
                $("<div class=\"datagrid-mask\"></div>").css({
                            display : "block",
                            width : wrap.width(),
                            height : wrap.height()
                        }).appendTo(wrap);
                $("<div class=\"datagrid-mask-msg\"></div>").html(opts.loadMsg).appendTo(wrap).css({
                            display : "block",
                            left : (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2,
                            top : (wrap.height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2
                        });
            }
        };
        function setLoadEnd() {
            _13c.find("div.datagrid-pager").pagination("loaded");
            _13c.find("div.datagrid-mask-msg").remove();
            _13c.find("div.datagrid-mask").remove();
        };
    };
    function _141(_142, _143) {
        var rows = $.data(_142, "datagrid").data.rows;
        var _144 = $.data(_142, "datagrid").panel;
        _143.rowspan = _143.rowspan || 1;
        _143.colspan = _143.colspan || 1;
        if (_143.index < 0 || _143.index >= rows.length) {
            return;
        }
        if (_143.rowspan == 1 && _143.colspan == 1) {
            return;
        }
        var _145 = rows[_143.index][_143.field];
        var tr = _144.find("div.datagrid-body tr[datagrid-row-index=" + _143.index + "]");
        var td = tr.find("td[field=" + _143.field + "]");
        td.attr("rowspan", _143.rowspan).attr("colspan", _143.colspan);
        td.addClass("datagrid-td-merged");
        for (var i = 1; i < _143.colspan; i++) {
            td = td.next();
            td.hide();
            rows[_143.index][td.attr("field")] = _145;
        }
        for (var i = 1; i < _143.rowspan; i++) {
            tr = tr.next();
            var td = tr.find("td[field=" + _143.field + "]").hide();
            rows[_143.index + i][td.attr("field")] = _145;
            for (var j = 1; j < _143.colspan; j++) {
                td = td.next();
                td.hide();
                rows[_143.index + i][td.attr("field")] = _145;
            }
        }
        setTimeout(function() {
                    _7d(_142);
                }, 0);
    };
    $.fn.datagrid = function(options, _147) {
        if (typeof options == "string") {
            return $.fn.datagrid.methods[options](this, _147);
        }
        options = options || {};
        return this.each(function() {
                    var _148 = $.data(this, "datagrid");
                    var opts;
                    if (_148) {
                        opts = $.extend(_148.options, options);
                        _148.options = opts;
                    } else {
                        opts = $.extend({}, $.fn.datagrid.defaults, $.fn.datagrid.parseOptions(this), options);
                        $(this).css("width", "").css("height", "");
                        var _149 = initGrid(this, opts.rownumbers);
                        if (!opts.columns) {
                            opts.columns = _149.columns;
                        }
                        if (!opts.frozenColumns) {
                            opts.frozenColumns = _149.frozenColumns;
                        }
                        $.data(this, "datagrid", {
                                    options : opts,
                                    panel : _149.panel,
                                    selectedRows : [],
                                    data : {
                                        total : 0,
                                        rows : []
                                    },
                                    originalRows : [],
                                    updatedRows : [],
                                    insertedRows : [],
                                    deletedRows : [],
                                    editingRows : []
                                });
                    }
                    drawGridFrame(this);
                    if (!_148) {
                        var data = _34(this);
                        if (data.total > 0) {
                            addData(this, data);
                            _12c(this);
                        }
                    }
                    _3(this);
                    if (opts.url) {
                        _139(this);
                    }
                    _5c(this);
                });
    };
    var _14a = {
        text : {
            init : function(_14b, _14c) {
                var _14d = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(_14b);
                return _14d;
            },
            getValue : function(_14e) {
                return $(_14e).val();
            },
            setValue : function(_14f, _150) {
                $(_14f).val(_150);
            },
            resize : function(_151, _152) {
                var _153 = $(_151);
                if ($.boxModel == true) {
                    _153.width(_152 - (_153.outerWidth() - _153.width()));
                } else {
                    _153.width(_152);
                }
            }
        },
        textarea : {
            init : function(_154, _155) {
                var _156 = $("<textarea class=\"datagrid-editable-input\"></textarea>").appendTo(_154);
                return _156;
            },
            getValue : function(_157) {
                return $(_157).val();
            },
            setValue : function(_158, _159) {
                $(_158).val(_159);
            },
            resize : function(_15a, _15b) {
                var _15c = $(_15a);
                if ($.boxModel == true) {
                    _15c.width(_15b - (_15c.outerWidth() - _15c.width()));
                } else {
                    _15c.width(_15b);
                }
            }
        },
        checkbox : {
            init : function(_15d, _15e) {
                var _15f = $("<input type=\"checkbox\">").appendTo(_15d);
                _15f.val(_15e.on);
                _15f.attr("offval", _15e.off);
                return _15f;
            },
            getValue : function(_160) {
                if ($(_160).attr("checked")) {
                    return $(_160).val();
                } else {
                    return $(_160).attr("offval");
                }
            },
            setValue : function(_161, _162) {
                if ($(_161).val() == _162) {
                    $(_161).attr("checked", true);
                } else {
                    $(_161).attr("checked", false);
                }
            }
        },
        numberbox : {
            init : function(_163, _164) {
                var _165 = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(_163);
                _165.numberbox(_164);
                return _165;
            },
            getValue : function(_166) {
                return $(_166).val();
            },
            setValue : function(_167, _168) {
                $(_167).val(_168);
            },
            resize : function(_169, _16a) {
                var _16b = $(_169);
                if ($.boxModel == true) {
                    _16b.width(_16a - (_16b.outerWidth() - _16b.width()));
                } else {
                    _16b.width(_16a);
                }
            }
        },
        validatebox : {
            init : function(_16c, _16d) {
                var _16e = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(_16c);
                _16e.validatebox(_16d);
                return _16e;
            },
            destroy : function(_16f) {
                $(_16f).validatebox("destroy");
            },
            getValue : function(_170) {
                return $(_170).val();
            },
            setValue : function(_171, _172) {
                $(_171).val(_172);
            },
            resize : function(_173, _174) {
                var _175 = $(_173);
                if ($.boxModel == true) {
                    _175.width(_174 - (_175.outerWidth() - _175.width()));
                } else {
                    _175.width(_174);
                }
            }
        },
        datebox : {
            init : function(_176, _177) {
                var _178 = $("<input type=\"text\" class=\"datagrid-editable-input\">").appendTo(_176);
                _178.datebox(_177);
                return _178;
            },
            destroy : function(_179) {
                $(_179).datebox("destroy");
            },
            getValue : function(_17a) {
                return $(_17a).val();
            },
            setValue : function(_17b, _17c) {
                $(_17b).val(_17c);
            },
            resize : function(_17d, _17e) {
                var _17f = $(_17d);
                if ($.boxModel == true) {
                    _17f.width(_17e - (_17f.outerWidth() - _17f.width()));
                } else {
                    _17f.width(_17e);
                }
            }
        },
        combobox : {
            init : function(_180, _181) {
                var _182 = $("<input type=\"text\">").appendTo(_180);
                _182.combobox(_181 || {});
                return _182;
            },
            destroy : function(_183) {
                $(_183).combobox("destroy");
            },
            getValue : function(_184) {
                return $(_184).combobox("getValue");
            },
            setValue : function(_185, _186) {
                $(_185).combobox("setValue", _186);
            },
            resize : function(_187, _188) {
                $(_187).combobox("resize", _188);
            }
        },
        combotree : {
            init : function(_189, _18a) {
                var _18b = $("<input type=\"text\">").appendTo(_189);
                _18b.combotree(_18a);
                return _18b;
            },
            destroy : function(_18c) {
                $(_18c).combotree("destroy");
            },
            getValue : function(_18d) {
                return $(_18d).combotree("getValue");
            },
            setValue : function(_18e, _18f) {
                $(_18e).combotree("setValue", _18f);
            },
            resize : function(_190, _191) {
                $(_190).combotree("resize", _191);
            }
        }
    };
    $.fn.datagrid.methods = {
        options : function(jq) {
            var options = $.data(jq[0], "datagrid").options;
            var panel_options = $.data(jq[0], "datagrid").panel.panel("options");
            var opts = $.extend(options, {
                        width : panel_options.width,
                        height : panel_options.height,
                        closed : panel_options.closed,
                        collapsed : panel_options.collapsed,
                        minimized : panel_options.minimized,
                        maximized : panel_options.maximized
                    });
            var pager = jq.datagrid("getPager");
            if (pager.length) {
                var pager_opts = pager.pagination("options");
                $.extend(opts, {
                            pageNumber : pager_opts.pageNumber,
                            pageSize : pager_opts.pageSize
                        });
            }
            return opts;
        },
        getPanel : function(jq) {
            return $.data(jq[0], "datagrid").panel;
        },
        getPager : function(jq) {
            return $.data(jq[0], "datagrid").panel.find("div.datagrid-pager");
        },
        getColumnFields : function(jq, frozen) {
            return ConvertColumns(jq[0], frozen);
        },
        getColumnOption : function(jq, fieldName) {
            return getColumnByField(jq[0], fieldName);
        },
        resize : function(jq, _198) {
            return jq.each(function() {
                        _3(this, _198);
                    });
        },
        load : function(jq, _199) {
            return jq.each(function() {
                        var opts = $(this).datagrid("options");
                        opts.pageNumber = 1;
                        var _19a = $(this).datagrid("getPager");
                        _19a.pagination({
                                    pageNumber : 1
                                });
                        _139(this, _199);
                    });
        },
        reload : function(jq, _19b) {
            return jq.each(function() {
                        _139(this, _19b);
                    });
        },
        fitColumns : function(jq) {
            return jq.each(function() {
                        _6e(this);
                    });
        },
        fixColumnSize : function(jq) {
            return jq.each(function() {
                        _31(this);
                    });
        },
        fixRowHeight : function(jq, _19c) {
            return jq.each(function() {
                        setGridHeight(this, _19c);
                    });
        },
        loadData : function(jq, data) {
            return jq.each(function() {
                        addData(this, data);
                        _12c(this);
                    });
        },
        getData : function(jq) {
            return $.data(jq[0], "datagrid").data;
        },
        getRows : function(jq) {
            return $.data(jq[0], "datagrid").data.rows;
        },
        getRowIndex : function(jq, id) {
            return _a2(jq[0], id);
        },
        getSelected : function(jq) {
            var rows = _a6(jq[0]);
            return rows.length > 0 ? rows[0] : null;
        },
        getSelections : function(jq) {
            return _a6(jq[0]);
        },
        clearSelections : function(jq) {
            return jq.each(function() {
                        removeSelected(this);
                    });
        },
        selectAll : function(jq) {
            return jq.each(function() {
                        _b2(this);
                    });
        },
        unselectAll : function(jq) {
            return jq.each(function() {
                        unSelectedAll(this);
                    });
        },
        selectRow : function(jq, _19d) {
            return jq.each(function() {
                        rowCheckedByIndex(this, _19d);
                    });
        },
        selectRecord : function(jq, id) {
            return jq.each(function() {
                        rowCheckedById(this, id);
                    });
        },
        unselectRow : function(jq, _19e) {
            return jq.each(function() {
                        _5b(this, _19e);
                    });
        },
        beginEdit : function(jq, _19f) {
            return jq.each(function() {
                        _d8(this, _19f);
                    });
        },
        endEdit : function(jq, _1a0) {
            return jq.each(function() {
                        _e2(this, _1a0, false);
                    });
        },
        cancelEdit : function(jq, _1a1) {
            return jq.each(function() {
                        _e2(this, _1a1, true);
                    });
        },
        getEditors : function(jq, _1a2) {
            return _fb(jq[0], _1a2);
        },
        getEditor : function(jq, _1a3) {
            return _100(jq[0], _1a3);
        },
        refreshRow : function(jq, _1a4) {
            return jq.each(function() {
                        var opts = $.data(this, "datagrid").options;
                        opts.view.refreshRow.call(opts.view, this, _1a4);
                    });
        },
        validateRow : function(jq, _1a5) {
            return _e1(jq[0], _1a5);
        },
        appendRow : function(jq, row) {
            return jq.each(function() {
                        _123(this, row);
                    });
        },
        deleteRow : function(jq, _1a6) {
            return jq.each(function() {
                        _11a(this, _1a6);
                    });
        },
        getChanges : function(jq, _1a7) {
            return _114(jq[0], _1a7);
        },
        acceptChanges : function(jq) {
            return jq.each(function() {
                        _12f(this);
                    });
        },
        rejectChanges : function(jq) {
            return jq.each(function() {
                        _131(this);
                    });
        },
        mergeCells : function(jq, _1a8) {
            return jq.each(function() {
                        _141(this, _1a8);
                    });
        },
        showColumn : function(jq, _1a9) {
            return jq.each(function() {
                        var _1aa = $(this).datagrid("getPanel");
                        _1aa.find("td[field=" + _1a9 + "]").show();
                        $(this).datagrid("getColumnOption", _1a9).hidden = false;
                        $(this).datagrid("fitColumns");
                    });
        },
        hideColumn : function(jq, _1ab) {
            return jq.each(function() {
                        var _1ac = $(this).datagrid("getPanel");
                        _1ac.find("td[field=" + _1ab + "]").hide();
                        $(this).datagrid("getColumnOption", _1ab).hidden = true;
                        $(this).datagrid("fitColumns");
                    });
        }
    };
    $.fn.datagrid.parseOptions = function(_1ad) {
        var t = $(_1ad);
        return $.extend({}, $.fn.panel.parseOptions(_1ad), {
                    fitColumns : (t.attr("fitColumns") ? t.attr("fitColumns") == "true" : undefined),
                    striped : (t.attr("striped") ? t.attr("striped") == "true" : undefined),
                    nowrap : (t.attr("nowrap") ? t.attr("nowrap") == "true" : undefined),
                    rownumbers : (t.attr("rownumbers") ? t.attr("rownumbers") == "true" : undefined),
                    singleSelect : (t.attr("singleSelect") ? t.attr("singleSelect") == "true" : undefined),
                    pagination : (t.attr("pagination") ? t.attr("pagination") == "true" : undefined),
                    remoteSort : (t.attr("remoteSort") ? t.attr("remoteSort") == "true" : undefined),
                    showFooter : (t.attr("showFooter") ? t.attr("showFooter") == "true" : undefined),
                    idField : t.attr("idField"),
                    url : t.attr("url")
                });
    };
    var _1ae = {
        render : function(grid, dataBody, frozen) {
            var opts = $.data(grid, "datagrid").options;
            var rows = $.data(grid, "datagrid").data.rows;
            var columns = $(grid).datagrid("getColumnFields", frozen);
            if (frozen) {
                if (!(opts.rownumbers || (opts.frozenColumns && opts.frozenColumns.length))) {
                    return;
                }
            }
            var tableHtml = ["<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>"];
            for (var i = 0; i < rows.length; i++) {
                var cls = (i % 2 && opts.striped) ? "class=\"datagrid-row-alt\"" : "";
                var rowStyle = opts.rowStyler ? opts.rowStyler.call(grid, i, rows[i]) : "";
                var styleHtml = rowStyle ? "style=\"" + rowStyle + "\"" : "";
                tableHtml.push("<tr datagrid-row-index=\"" + i + "\" " + cls + " " + styleHtml + ">");
                tableHtml.push(this.renderRow.call(this, grid, columns, frozen, i, rows[i]));
                tableHtml.push("</tr>");
            }
            tableHtml.push("</tbody></table>");
            $(dataBody).html(tableHtml.join(""));
        },
        renderFooter : function(_1b6, _1b7, _1b8) {
            var opts = $.data(_1b6, "datagrid").options;
            var rows = $.data(_1b6, "datagrid").data.footer || [];
            var _1b9 = $(_1b6).datagrid("getColumnFields", _1b8);
            var _1ba = ["<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>"];
            for (var i = 0; i < rows.length; i++) {
                _1ba.push("<tr datagrid-row-index=\"" + i + "\">");
                _1ba.push(this.renderRow.call(this, _1b6, _1b9, _1b8, i, rows[i]));
                _1ba.push("</tr>");
            }
            _1ba.push("</tbody></table>");
            $(_1b7).html(_1ba.join(""));
        },
        renderRow : function(grid, columns, frozen, rowIndex, rowData) {
            var opts = $.data(grid, "datagrid").options;
            var cc = [];
            //如果是固定列，且有需要设置行号，那么增加行号设置；
            if (frozen && opts.rownumbers) {
                var rowNo = rowIndex + 1;
                if (opts.pagination) {
                    rowNo += (opts.pageNumber - 1) * opts.pageSize;
                }
                cc.push("<td class=\"datagrid-td-rownumber\"><div class=\"datagrid-cell-rownumber\">" + rowNo
                        + "</div></td>");
            }
            for (var i = 0; i < columns.length; i++) {
                var colName = columns[i];
                var col = $(grid).datagrid("getColumnOption", colName);
                if (col) {
                    var styleScripe = col.styler ? (col.styler(rowData[colName], rowData, rowIndex) || "") : "";
                    var styleHtml = col.hidden ? "style=\"display:none;" + styleScripe + "\"" : (styleScripe
                            ? "style=\"" + styleScripe + "\""
                            : "");
                    cc.push("<td field=\"" + colName + "\" " + styleHtml + ">");
                    var divStyle = "width:" + (col.boxWidth) + "px;";
                    divStyle += "text-align:" + (col.align || "left") + ";";
                    divStyle += opts.nowrap == false ? "white-space:normal;" : "";
                    cc.push("<div style=\"" + divStyle + "\" ");
                    if (col.checkbox) {
                        cc.push("class=\"datagrid-cell-check ");
                    } else {
                        cc.push("class=\"datagrid-cell ");
                    }
                    cc.push("\">");
                    if (col.checkbox) {
                        cc.push("<input type=\"checkbox\"/>");
                    } else {
                        if (col.formatter) {
                            cc.push(col.formatter(rowData[colName], rowData, rowIndex));
                        } else {
                            cc.push(rowData[colName]);
                        }
                    }
                    cc.push("</div>");
                    cc.push("</td>");
                }
            }
            return cc.join("");
        },
        refreshRow : function(_1c4, _1c5) {
            var opts = $.data(_1c4, "datagrid").options;
            var _1c6 = $(_1c4).datagrid("getPanel");
            var rows = $(_1c4).datagrid("getRows");
            var _1c7 = opts.rowStyler ? opts.rowStyler.call(_1c4, _1c5, rows[_1c5]) : "";
            var tr = _1c6.find("div.datagrid-body tr[datagrid-row-index=" + _1c5 + "]");
            tr.attr("style", _1c7 || "");
            tr.children("td").each(function() {
                        var td = $(this);
                        var cell = td.find("div.datagrid-cell");
                        var _1c8 = td.attr("field");
                        var col = $(_1c4).datagrid("getColumnOption", _1c8);
                        if (col) {
                            var _1c9 = col.styler ? col.styler(rows[_1c5][_1c8], rows[_1c5], _1c5) : "";
                            td.attr("style", _1c9 || "");
                            if (col.hidden) {
                                td.hide();
                            }
                            if (col.formatter) {
                                cell.html(col.formatter(rows[_1c5][_1c8], rows[_1c5], _1c5));
                            } else {
                                cell.html(rows[_1c5][_1c8]);
                            }
                        }
                    });
            $(_1c4).datagrid("fixRowHeight", _1c5);
        },
        onBeforeRender : function(_1ca, rows) {
        },
        onAfterRender : function(grid) {
            var opts = $.data(grid, "datagrid").options;
            if (opts.showFooter) {
                var footer = $(grid).datagrid("getPanel").find("div.datagrid-footer");
                footer.find("div.datagrid-cell-rownumber,div.datagrid-cell-check").css("visibility", "hidden");
            }
        }
    };
    $.fn.datagrid.defaults = $.extend({}, $.fn.panel.defaults, {
                frozenColumns : null,
                columns : null,
                fitColumns : false,
                toolbar : null,
                striped : false,
                method : "post",
                nowrap : true,
                idField : null,
                url : null,
                loadMsg : "Processing, please wait ...",
                rownumbers : false,
                singleSelect : false,
                pagination : false,
                pageNumber : 1,
                pageSize : 10,
                pageList : [10, 20, 30, 40, 50],
                queryParams : {},
                sortName : null,
                sortOrder : "asc",
                remoteSort : true,
                showFooter : false,
                rowStyler : function(_1cd, _1ce) {
                },
                editors : _14a,
                view : _1ae,
                onBeforeLoad : function(_1cf) {
                },
                onLoadSuccess : function() {
                },
                onLoadError : function() {
                },
                onClickRow : function(_1d0, _1d1) {
                },
                onDblClickRow : function(_1d2, _1d3) {
                },
                onSortColumn : function(sort, _1d4) {
                },
                onResizeColumn : function(_1d5, _1d6) {
                },
                onSelect : function(_1d7, _1d8) {
                },
                onUnselect : function(_1d9, _1da) {
                },
                onSelectAll : function(rows) {
                },
                onUnselectAll : function(rows) {
                },
                onBeforeEdit : function(_1db, _1dc) {
                },
                onAfterEdit : function(_1dd, _1de, _1df) {
                },
                onCancelEdit : function(_1e0, _1e1) {
                },
                onHeaderContextMenu : function(e, _1e2) {
                },
                onRowContextMenu : function(e, _1e3, _1e4) {
                }
            });
})(jQuery);
